﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace InvoiceInvoker.Logic
{
	public static class VatRatesProvider
	{
		public static List<string> GetVatRates()
		{
			string vatRates = ConfigurationManager.AppSettings["VatRates"];
			string[] separator = { ", ", "," };
			return vatRates.Split(separator, StringSplitOptions.RemoveEmptyEntries).ToList();
		}

		public static int GetVatPercentage(string vatRate)
		{
			int result = 0;
			string vatPercentage = string.Empty;

			if (vatRate.EndsWith(" %"))
				vatPercentage = vatRate.Substring(0, vatRate.Length - 2);
			else if (vatRate.EndsWith("%"))
				vatPercentage = vatRate.Substring(0, vatRate.Length - 1);

			int.TryParse(vatPercentage, out result);

			return result;
		}
	}
}
